﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using EQ1.Elements;
using com.woodsoft.core.Files;
using EQ1.Objects;

namespace EQ1.Elements {
  public class ListboxColumn : UIClass , IUIElement<ListboxColumn> {
    public ListboxColumn ( UIDocument doc , string name )
      : base( doc , name ) {
    }
    public ListboxColumn ( UIDocument doc )
      : this( doc , "ListboxColumn" ) {
    }

    #region IUIElement<ListboxColumn> Members

    public void Validate ( ListboxColumn val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        ListboxColumn el = new ListboxColumn( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    public void Copy ( ListboxColumn val ) {
      base.Copy( val );

      if( val.Header != null )
        this.Header = val.Header;
      if( val.Heading != null )
        this.Heading = val.Heading;
      if( val.Width != null )
        this.Width = val.Width;
      if( val.Sortable != null )
        this.Sortable = val.Sortable;
      if( val.DataType != null )
        this.DataType = val.DataType;
      if( val.Tooltip != null )
        this.Tooltip = val.Tooltip;

    }

    #endregion

    public string Header {
      get {
        return this.GetElement( "Header" ).InnerText;
      }
      set {
        this.Validate( "Header" , value );
      }
    }
    public string Heading {
      get {
        return this.GetElement( "Heading" ).InnerText;
      }
      set {
        this.Validate( "Heading" , value );
      }
    }
    public int? Width {
      get {
        return int.Parse( this.GetElement( "Width" ).InnerText );
      }
      set {
        this.Validate( "Width" , value.ToString() );
      }
    }
    public bool? Sortable {
      get {
        return bool.Parse( this.GetElement( "Sortable" ).InnerText );
      }
      set {
        this.Validate( "Sortable" , value.ToString() );
      }
    }
    public string DataType {
      get {
        return this.GetElement( "DataType" ).InnerText;
      }
      set {
        this.Validate( "DataType" , value );
      }
    }
    public string Tooltip {
      get {
        return this.GetElement( "Tooltip" ).InnerText;
      }
      set {
        this.Validate( "Tooltip" , value );
      }
    }
  }
}
